<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="number" id="numberInput">
    <button onclick="calculateFactorial()">阶乘</button>
    =
    <span id="result"></span>
    <script>
        function calculateFactorial() {
            var number = document.getElementById('numberInput').value;
            number = parseInt(number);
            if (isNaN(number)) {
                alert("请输入一个有效的数字");
                return;
            }
            if(number < 0) {
                alert("请输入一个有效的数字");
                return;
            } else if (number == 0) {
                factorial = 1;
            } else {
                var factorial = 1;
                for (var i = 1; i <= number; i++) {
                    factorial *= i;
                }
            }
            document.getElementById('result').innerText = factorial;
        }
    </script>
</body>
</html>